"""
保险公司管理相关的 API 端点
"""
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, status as status_module, Query
from ....crud.insurance_company import insurance_companie_curd
from ....models.insurance_company import InsuranceCompany
from ....models.user import User
from ....schemas import BaseResponse
from ....schemas.insurance_company import InsuranceCompanyDetailResponse

router = APIRouter()


@router.get(
    "/",
    # response_model=BaseResponse[List[InsuranceCompanyDetailResponse]],
    summary="获取保险公司及产品列表",
    description="获取保险公司及产品列表"
)
async def get_insurance_companies(
        skip: int = Query(0, ge=0, description="跳过的记录数"),
        limit: int = Query(100, ge=1, le=100, description="返回的记录数"),
        # current_user: User = Depends(get_current_active_user)
):
    """获取保险公司及产品列表"""
    try:
        companies = await insurance_companie_curd.get_insurance_companies(skip, limit)
        return {
            "code": 200,
            "data": companies,
            "msg": "获取保险公司及产品列表成功"
        }
    except Exception as e:
        raise HTTPException(
            status_code=status_module.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=str(e)
        )


@router.get(
    "/search",
    # response_model=BaseResponse[List[PolicyDetailResponse]],
    summary="查找保险公司及产品列表",
    description="查找保险公司及产品列表"
)
async def search_insurance_companies(
        company_id: str = Query(None, description="保险公司编号"),
        company_name: str = Query(None, description="保险公司名称"),
        company_phone: str = Query(None, description="保险公司电话"),
        company_email: str = Query(None, description="保险公司邮箱"),
        company_address: str = Query(None, description="保险公司地址"),
        skip: int = Query(0, ge=0, description="跳过的记录数"),
        limit: int = Query(100, ge=1, le=100, description="返回的记录数"),
        # current_user: User = Depends(get_current_active_user)
):
    """查找保险公司及产品列表"""
    return {
        "code": 200,
        "data": await InsuranceCompany.filter(
            company_id=company_id,
            company_name=company_name,
            company_phone=company_phone,
            company_email=company_email,
            company_address=company_address
        ).limit(limit).offset(skip),
        "msg": "查找保险公司及产品列表成功"
    }


@router.post(
    "/",
    # response_model=BaseResponse[PolicyDetailResponse],
    summary="创建保险公司",
    description="创建保险公司,需管理员权限"
)
async def create_insurance_company(
        # company_data: InsuranceCompany,
        # current_user: User = Depends(require_role("admin"))
):
    """创建保险公司"""
    return {
        "code": 200,
        # "data": await InsuranceCompany.create(**company_data.dict()),
        "msg": "创建保险公司成功"
    }


@router.put(
    "/{company_id}",
    # response_model=BaseResponse[PolicyDetailResponse],
    summary="更新保险公司",
    description="更新保险公司,需管理员权限"
)
async def update_insurance_company(
        company_id: str,
        # company_data: InsuranceCompany,
        # current_user: User = Depends(require_role("admin"))
):
    """更新保险公司"""
    return {}


@router.delete(
    "/{company_id}",
    # response_model=BaseResponse[PolicyDetailResponse],
    summary="删除保险公司",
    description="删除保险公司,需管理员权限"
)
async def delete_insurance_company(
        company_id: str,
        # current_user: User = Depends(require_role("admin"))
):
    """删除保险公司"""
    return {}
